<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/taglibs.jsp"%>
<%@ page import="com.msmall.base.rms.po.Module" language="java"%>
<c:set var="TYPE_MODULE" value="<%=Module.TYPE_MODULE%>"></c:set>
<c:set var="TYPE_FUNCTION" value="<%=Module.TYPE_FUNCTION%>"></c:set>
<c:set var="TYPE_HELPER" value="<%=Module.TYPE_HELPER%>"></c:set>

<script type="text/javascript">
function cascadeSelect(level){
	var currentId = $("#module_id").val();
	var selectedId = $("#select_level"+level).val();
	if(selectedId == undefined){
		selectedId = 0;
	}
	if(level == 0){
		$("#select_level1").empty();
		$("#select_level2").empty();
		$("#select_level3").empty();
	}
	if(level == 1){
		$("#select_level2").empty();
		$("#select_level3").empty();
	}
	if(level == 2){
		$("#select_level3").empty();
	}
	var childSelect = "#select_level" + (level+1);
	$.ajax({
		dataType:'json',
		type: "POST",
		url: siteServer + '/rms/module/cascade.do?type=1&moduleid='+selectedId,
		async: false,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    alert("Connection error : " + textStatus);
		    alert(errorThrown);
		},
		success: function(data){
			$(childSelect).append("<option value='-1'>选择</option>");
			var items = data.items;
			for(var i=0; i<items.length; i++){
				if(items[i].id == currentId){
					$(childSelect).append("<option value='" + items[i].id +"' selected='selected'>" + items[i].moduleName +"</option>");
				}else{
					$(childSelect).append("<option value='" + items[i].id +"'>" + items[i].moduleName +"</option>");
				}
			}
		}
	});
}

$("#saveEntity").click(function(){
	var level1 = $("#select_level1").val();
	var level2 = $("#select_level2").val();
	var level3 = $("#select_level3").val();
	if(level3 > 0){
		$("#module_parentid").val(level3);
	}else if(level2 > 0){
		$("#module_parentid").val(level2);
	}else if(level1 > 0){
		$("#module_parentid").val(level1);
	}
	$.ajax({
		cache: true,
		type: "POST",
		url: $('#entityForm').attr('action'),
		data:$('#entityForm').serialize(),
		async: false,
		error: function(error) {
		    alert("Connection error");
		},
		success: function(data) {
		    $("#main_main").html(data);
		}
	});
});
$(document).ready(function(){
	cascadeSelect(0);
});
</script>
<form id="entityForm" name="entityForm" action="<c:url value='/rms/module/save.do'/>">
	<input type="hidden" id="module_id" name="id" value="${entity.id}"/>
	<input type="hidden" id="module_parentid" name="parentid" value="${entity.parentid}"/>
	<table class="tableform" width="100%" cellspacing="0" cellpadding="0" border="0">
		<tbody>
		<tr>
			<td width="17%">
				模块名称：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<input id="moduleName" class="w200" type="text" name="moduleName" value="${entity.moduleName }">
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td width="17%">
				模块类型：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<select name="type">
					<option value="${TYPE_MODULE}" <c:if test="${entity.type == TYPE_MODULE}">selected="selected"</c:if>>模块</option>
					<option value="${TYPE_FUNCTION}" <c:if test="${entity.type == TYPE_FUNCTION}">selected="selected"</c:if>>功能点</option>
					<option value="${TYPE_HELPER}" <c:if test="${entity.type == TYPE_HELPER}">selected="selected"</c:if>>辅助功能</option>
				</select>
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td width="17%">
				父模块：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<select id="select_level1" onChange="javascript:cascadeSelect(1)">
				</select>
				<select id="select_level2" onChange="javascript:cascadeSelect(2)">
				</select>
				<select id="select_level3">
				</select>
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td width="17%">
				路径：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<input id="url" class="w200" type="text" name="url" value="${entity.url }">
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td width="17%">
				备注：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<textarea id="remark" class="w200" name="remark"">
					<c:out value="${entity.remark}"></c:out>
				</textarea>
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
			<input id="saveEntity" class="btn Borange fw7 mb20" type="button" value="保   存">
			</td>
		</tr>
		</tbody>
	</table>
</form>
